#ifndef IMAGEGRIDDISPLAY_H
#define IMAGEGRIDDISPLAY_H

#include <eiklbo.h>       // for MEikListBoxObserver
#include <AknIconArray.h> // for CArrayPtr
#include <akngrid.h> // CAknGrid

//forward reference
class CAknGrid;
class CGulIcon;
class CImageDecoder;

class MGridInterface
	{
public:
	virtual void UpdateGrid(CFbsBitmap& aBitMap) = 0;
	virtual void ShowErrorMessage(TInt aError) = 0;
	};

class CImageConvertor : public CActive
	{
public:
	 static CImageConvertor* NewL(MGridInterface&   aGridInterface);
	 static CImageConvertor* NewLC(MGridInterface&  aGridInterface);
	 ~CImageConvertor();
	 
	 void StartImageConversionL(TFileName& aFilepath);
	 
private: 
	 // from CActive
	 void RunL();
	 void DoCancel();
	 virtual TInt RunError(TInt aError);
	
	 void ConstructL();
	 CImageConvertor(MGridInterface& aGridInterface);
	 
private:
	 RFs                          iFsSession;
	 TBool						  iErrorStatus;
	 MGridInterface&              iGridInterface;
	 CImageDecoder*               iImageDecoder;
	 //this var is required to delete CFbsBitmap object if RunL leaves.
	 CFbsBitmap*          		  iCreatedFbsBitmap;
	 RPointerArray<CFbsBitmap>    iBitmapPtr;
	};

class CImageGridDispaly :public CCoeControl,MEikListBoxObserver,MGridInterface
	{
	
public: // Constructors and destructor

        static CImageGridDispaly* NewL( const TRect& aRect );
        static CImageGridDispaly* NewLC( const TRect& aRect );
        CImageGridDispaly();  //TODO Need to move it to private
        void ConstructL( const TRect& aRect );
        ~CImageGridDispaly();
        
public:     
        void UpdateGrid(CFbsBitmap& aBitMap);
        void ShowErrorMessage(TInt aError);
        
		/**
   		* From CoeControl, HandleResourceChange.
	    * Called by framework when the view layout is changed.
	    */
	    virtual void HandleResourceChange( TInt aType );
       
private: 
	    void MakeGridBoxL();
        CDesCArray* GetArrayL(CArrayPtr<CGulIcon>* aIcon, const TSize& aIconsize);
        
        TInt ImageCount();
        void ImageName(TFileName& aFilename,TInt aIndex);
        void ReadImageDirectoryL(TFileName& aFilepath);
        void PlainImageName(TFileName& aFilename,TInt aIndex);
        
        //from MEikListBoxObserver,HandleListBoxEventL.
        void HandleListBoxEventL( CEikListBox* aListBox,TListBoxEvent aListBoxEvent );
        
        /**
         * From CoeControl,SizeChanged.
        */
           void SizeChanged();
        
        /**
         * From CCoeControl,Draw.
        */
        void Draw( const TRect& aRect ) const;
   	   
	    void FocusChanged( TDrawNow aDrawNow );
	   
	    /**
		* From CCoeControl,CountComponentControls.
		*/
	    TInt CountComponentControls() const;

	    /**
		* From CCoeControl,ComponentControl.
		*/
		CCoeControl* ComponentControl( TInt aIndex ) const;
		
	    
	 //   void FocusChanged( TDrawNow aDrawNow );

		
		void SetEmptyTextL();
		
private:
	        void SetGridTextFont();
 
public:
       /**
          * iGrid, the grid shown in this view.
          */
          CAknGrid* iGrid; //need to make it private
   private: //data
  

       /**
       * iGridM, model for iGrid
       */
       CAknGridM* iGridM;

       /**
       * iVerticalOrientation, vertical orietation status
       */
       TBool iVerticalOrientation;

       /**
       * iLeftToRight, fill order status
       */
       TBool iLeftToRight;

       /**
       * iTopToBottom, fill order status
       */
       TBool iTopToBottom;

       /**
       * iNumOfColumns, number of grid columns
       */
       TInt iNumOfColumns;

       /**
       * iNumOfRows, number of grid rows
       */
       TInt iNumOfRows;

       /**
       * iContentType, type of content
       */
       TInt iContentType;

       /**
       * iSizeOfCell, size of grid cell
       */
       TSize iSizeOfCell;

       /**
       * iNumOfItems, number of grid items
       */
       TInt iNumOfItems;

       /**
       * iVerticalScrollingType, scrolling type
       */
       CAknGridView::TScrollingType iVerticalScrollingType;

       /**
       * iHorizontalScrollingType, scrolling type
       */
       CAknGridView::TScrollingType iHorizontalScrollingType;

       /**
       * iBitmap, grid icon
       */
       CFbsBitmap* iBitmap;

       /**
       * iMask, mask of grid icon
       */
       CFbsBitmap* iMask;

       /**
       * iNaviDecorator
       */
     
       TBool					iErrorStatus;
       RArray<TFileName>    	iFiles;
       CArrayPtr<CGulIcon>* 	iArrayicons;
       CImageConvertor*     	iImageConvertor;
       TInt                 	iArrayIndex;
       CGulIcon*            	iDefaultGulIcon;
                             
	};

#endif

// End of File
